import { _decorator, Component, Node, Prefab, RigidBody, BoxCharacterController, BoxColliderComponent } from 'cc';

import { poolManager } from '../../../../Framework/Scripts/Managers/poolManager';
import { enemyBase } from '../enemyBase';

import { Missile } from '../weaponCtrl/missile';



/** 
  周无邪出品
  本源码用于学习研究使用。
  作者联系方式：tuya7078（微信）。
 */
const { ccclass, property } = _decorator;

@ccclass('javelin')
export class javelin extends enemyBase {

    @property(Prefab)
    public pfWeapon: Prefab = null!;//武器预制体
    @property(Node)
    public ndRightHand: Node = null!;//右手节点


    @property(Node)
    private weaponNode: Node = null

    onLoad() {

        super.onLoad()
        //   this.weaponNode = poolManager.instance.getNode(this.pfWeapon, this.ndRightHand)

        //     const ts:Missile= this.weaponNode.getComponent(Missile)
        //     if(ts){
        //          ts.isHand=true

        //     }


        // this.weaponNode.getComponent(RigidBody).destroy()
        // this.weaponNode.getComponent(BoxColliderComponent).destroy()


    }




    start() {



    }

    attack() {
        super.attack()
        //  this.NavTs.StopNav()
        this.node.lookAt(this.attackTarget.getWorldPosition())
        this.weaponNode.active = true
        this.enemyModel.playAni(this.attackAni1, true)



    }

    protected friendly_pursuit() {

        this.weaponNode.active = true
        super.friendly_pursuit()
    }
    protected pursuit_building() {
        this.weaponNode.active = true
        super.pursuit_building()

    }

    protected enemy_pursuit() {
        this.weaponNode.active = true
        super.enemy_pursuit()
    }
    public attickCallback() {

    



        this.weaponNode.active = false

        const n: Node = poolManager.instance.getNode(this.pfWeapon, this.node.parent)
        n.setWorldPosition(this.ndRightHand.getWorldPosition())
        n.eulerAngles = this.ndRightHand.eulerAngles


        const ts: Missile = n.getComponent(Missile)
        if (ts) {

            ts.reset()
            ts.throwMissile(this.attackTarget.getWorldPosition(), 9, () => {


            }, this.node, this, this.attackTarget)
        }
    }//攻击回调
    update(dt: number) {
        super.update(dt)
    }
}


